<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新增修改岗位')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>工号：</p>
                            <input type="text" name="badge"/>
                        </li>
                        <li>
                            <p>姓名：</p>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addEditJob()">
                <i class="fa fa-plus"></i> 添加岗位
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>

<script th:inline="javascript">
    var prefix = ctx + 'job/admin';
    $(function () {
        queryData();
    })

    function queryData() {
        var columns = [];
        var checkbox = {checkbox: true};
        var jobId = {field: 'jobId', title: '岗位编码'};
        var title = {field: 'title', title: '岗位名称'};
        var JobAbbr = {field: 'JobAbbr', title: '岗位简称'};
        var JobGradeTitle = {field: 'JobGradeTitle', title: '岗位级别'};
        var JobTypeTitle = {field: 'JobTypeTitle', title: '岗位类型'};
        var compTitle = {field: 'compTitle', title: '所属公司'};
        var DepIdTitle = {field: 'DepIdTitle', title: '所属部门'};
        var AdminIDTitle = {field: 'AdminIDTitle', title: '上级岗位'};
        var Jobnum = {field: 'Jobnum', title: '编制人数'};
        var num = {field: 'num', title: '在岗人数'};
        var jobText = {field: 'jobText', title: '岗位说明'};
        var effectdate = {field: 'effectdate', title: '创建日期'};
        var remark = {field: 'remark', title: '备注'};


        columns.push(checkbox,jobId,title,JobAbbr,JobGradeTitle,JobTypeTitle,compTitle,DepIdTitle);
        columns.push(AdminIDTitle,Jobnum,num,jobText,effectdate,remark);

        var options = {
            code: "jobId",
            uniqueId: "jobId",
            url: prefix + '/findEditJobList',
            modalName: "添加修改岗位",
            height: $(window).height() - 110,
            columns: columns
        };
        $.table.init(options);
    }

    function addEditJob() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择数据!");
            return;
        }
        var allJob = "";
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allJob += row[i].jobId
            } else {
                allJob += row[i].jobId + ","

            }
        }

        $.ajax({
            async: false,
            url: prefix + "/addEditJob?type=2",
            data: {
                "allJob": allJob
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                //todo 这里需要判断data返回值
                if (data.code == 0) {
                    $.modal.alertWarning("添加成功！");
                    $.modal.close();
                    $.modal.reload();
                } else if (data.code == 500) {
                    $.modal.alertWarning("服务繁忙");
                } else {
                    $.modal.alertWarning(data.message);
                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

    function submitHandler() {
        addEditDep();
    }


</script>
</body>
</html>